#pragma once

extern "C"
{
    typedef struct
    {
        UINT32 PWM_CR;
        UINT32 PWM_SR;
        UINT32 PWM_IR;
        UINT32 PWM_SAR;
        UINT32 PWM_PR;
        UINT32 PWM_CNR;
    } PWM_REGS, *LPPWM_REGS;

    // PwmInit
    // Must be called before anything else
    // pwmIndex: 1..4
    // ret: FALSE on error (GetLastError() will return error code)
    BOOL PwmInit(DWORD pwmIndex);

    // PwmDeinit
    // Must be called when PWM is no longer needed (cleans up handles etc)
    // pwmIndex: 1..4
    // ret: FALSE on error (GetLastError() will return error code)
    BOOL PwmDeinit(DWORD pwmIndex);

    // PwmStart/PwmStartDuration
    // Starts the PWM, optionally for a duration in mS.
    // pwmIndex: 1..4
    // Frequency: Required frequency
    // DutyCycle: Required dutycycle (in percent)
    // Duration: Duration of output signal in mS.
    // ret: FALSE on error (GetLastError() will return error code)
    BOOL PwmStart(DWORD pwmIndex, DWORD Frequency, DWORD DutyCycle);
    BOOL PwmStartDuration(DWORD pwmIndex, DWORD Frequency, DWORD DutyCycle, DWORD Duration);

    // PwmStop
    // Stops the PWM
    // pwmIndex: 1..4
    // ret: FALSE on error (GetLastError() will return error code)
    BOOL PwmStop(DWORD pwmIndex);

    // PwmReset
    // Resets the PWM
    // pwmIndex: 1..4
    // ret: FALSE on error (GetLastError() will return error code)
    BOOL PwmReset(DWORD pwmIndex);

    // PwmReadRegisters
    // Gets the PWM registers
    // pwmIndex: 1..4
    // pPwmRegisters: pointer to PWM_REGS structure to receive the register values
    // ret: FALSE on error (GetLastError() will return error code)
    BOOL PwmReadRegisters(DWORD pwmIndex, LPPWM_REGS pPwmRegisters);
}